//
//    Copyright (C) 2012  OinkStudio
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package game;

import java.io.Serializable;

public class Obolo implements Cloneable, Serializable {

	private Skill north, south, east, west;
	private int owner;

	private void putSkillsToObolo(Skill[] skills) {
		north = skills[0];
		south = skills[1];
		east = skills[2];
		west = skills[3];
	}

	public boolean beEquals(Obolo compareObolo) {
		boolean serIgual = false;
		if (compareObolo != null) {
			if (north.beEquals(compareObolo.getNorth())
					&& south.beEquals(compareObolo.getSouth())
					&& east.beEquals(compareObolo.getEast())
					&& west.beEquals(compareObolo.getWest()))
				serIgual = true;
		}
		return serIgual;
	}

	public Obolo(String[] skills) throws IllegalArgumentException {

		Skill[] skillsNames = new Skill[4];
		for (int i = 0; i < skills.length; i++) {
			try {
				int SkillNum = Integer.parseInt(skills[i]);
				skillsNames[i] = new SkillNumber(SkillNum);
			} catch (IllegalArgumentException e) {
				if (skills[i].equals("sword"))
					skillsNames[i] = new SkillSword("sword");
				if (skills[i].equals("shield"))
					skillsNames[i] = new SkillShield("shield");
				if (skills[i].equals("twins"))
					skillsNames[i] = new SkillTwins("twins");
			}
		}
		putSkillsToObolo(skillsNames);

	}

	public int getOwner() {
		return owner;
	}

	public Skill getNorth() {
		return north;
	}

	public void setNorth(Skill newSkill) {
		north = newSkill;
	}

	public void setSouth(Skill newSkill) {
		south = newSkill;
	}

	public Skill getSouth() {
		return south;
	}

	public Skill getEast() {
		return east;
	}

	public void setEast(Skill newSkill) {
		east = newSkill;
	}

	public Skill getWest() {
		return west;
	}

	public void setWest(Skill newSkill) {
		west = newSkill;
	}

	public void setOwner(int newOwner) {
		owner = newOwner;
	}

	public String getNorthName() {
		return north.getName();
	}

	public String getSouthName() {
		return south.getName();
	}

	public String getEastName() {
		return east.getName();
	}

	public String getWestName() {
		return west.getName();
	}

	public Obolo clone() throws CloneNotSupportedException {
		Obolo toClone = (Obolo) super.clone();
		toClone.setEast(east.clone());
		toClone.setNorth(north.clone());
		toClone.setWest(west.clone());
		toClone.setSouth(south.clone());
		toClone.setOwner(owner);
		return toClone;
	}
}
